package com.dayuanit.service.impl;

import com.dayuanit.controller.request.AddEquipmentPlanParam;
import com.dayuanit.dao.EquipmentPlanDao;
import com.dayuanit.entity.EquipmentPlan;
import com.dayuanit.service.EquipmentPlanService;
import com.dayuanit.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class EquipmentPlanServiceImpl implements EquipmentPlanService {

    @Autowired(required = false)
    EquipmentPlanDao equipmentPlanDao;


    @Override
    public PageInfo queryEquipmentListByPlanNameOrEquipmentName(String planName, String equipmentName, Integer page, Integer pageSize) {
        Integer count = equipmentPlanDao.countByPlanNameOrEquipmentName(planName, equipmentName);
        PageInfo pageInfo = new PageInfo<>().setPageNo(page).setPageSize(pageSize).setTotalCount(count);
        if(count == 0) {
            return pageInfo.setData(new ArrayList());
        }
        List<EquipmentPlan> planList = equipmentPlanDao.queryPlanPage(planName,equipmentName,pageInfo.limitStart(),pageInfo.limitEnd());
        return pageInfo.setData(planList);
    }


    @Override
    public void addEquipmentPlan(AddEquipmentPlanParam param) {
        EquipmentPlan plan = new EquipmentPlan();
        plan.setPlanName(param.getPlanName());
        plan.setEquipmentName(param.getEquipmentName());
        plan.setColor(param.getColor());
        plan.setSize(param.getSize());
        plan.setQuantity(param.getQuantity());
        plan.setAddTime(new Date());
        plan.setLastUpdateTime(new Date());
        plan.setIsDelete(0);
        equipmentPlanDao.insert(plan);
    }


    @Override
    public void batchRemove(List<Long> idList) {
        if(idList.size() == 0) {
            return;
        }
        equipmentPlanDao.batchRemove(idList);
    }
}
